package com.feihao.zhou.TCP.demo02;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket server = new ServerSocket(10088);

        Socket socket = server.accept();

        InputStream inputStream = socket.getInputStream();
        int len;
        byte[] bytes = new byte[1024];

        while ((len = inputStream.read(bytes))!=-1){
            System.out.println(new String(bytes,0,len));
        }

        //给客户端回写：
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("收到谢谢！".getBytes());
        outputStream.close();

        outputStream.close();
        inputStream.close();
        server.close();
        socket.close();
    }
}
